#include "counter.h"
#include "tim.h"
#include "usart.h"
#include "oled_spi.h"

uint16_t CountThis, CountLast, CountDis;
extern uint8_t Leaves, ModuleFlag;
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
    if(ModuleFlag == 0){
        CountThis = htim2.Instance->CNT;}
    else{
        CountThis = htim1.Instance->CNT;}
    CountDis = (CountThis - CountLast)/Leaves;
//    printf("\t%d r/s\r\n",CountDis);
    OLED_ShowNum(48,0,CountDis,3,16);
    OLED_Refresh();
    CountLast = CountThis;
}

extern uint8_t TurnFlag;
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
    if(GPIO_Pin == KEY_Z_Pin)
    {
        if(TurnFlag == 1)TurnFlag = 0;
        else TurnFlag = 1;
        OLED_DisplayTurn(TurnFlag);
        HAL_Delay(100);
    }
}
